package com.east.study;

import com.east.study.EastStudy.BaseColumns;
import com.east.study.EastStudy.Course;
import com.east.study.EastStudy.Grade;
import com.east.study.EastStudy.Join;
import com.east.study.EastStudy.Lesson;
import com.east.study.EastStudy.Subject;
//import com.east.study.EastStudy.Version;

public final class Upgrade {
    // Upgrade URL format

   // public static final String UPGRADE_URL_FORMAT = "http://srcdown.tqpad.com/index.php?gradeid=%d&subjectid=%d&"+
   //     "gsvid=%d&courseid=%d&lessonid=%d";
	
    public static final String UPGRADE_URL_FORMAT = "http://hebjs.7east.com/shop/admin/notice!xmltest.do";//"http://study.tqpad.com/padhgvideo/source.php?tqpadsn=%s&tqpadmac=%s&tqpadsr=%s&gradeid=%d&subjectid=%d&"+
    //"gsvid=%d&courseid=%d&lessonid=%d";
    // Upgrade select statement
    public static final String UPGRADE_STATEMENT  = "SELECT MAX(_id) FROM " + Grade.TABLE_NAME +
        " UNION ALL " + "SELECT MAX(" + BaseColumns.COLUMN_ID + ") FROM " + Subject.TABLE_NAME +
//        " UNION ALL " + "SELECT MAX(" + BaseColumns.COLUMN_ID + ") FROM " + Version.TABLE_NAME +
        " UNION ALL " + "SELECT MAX(" + BaseColumns.COLUMN_ID + ") FROM " + Join.TABLE_NAME +
        " UNION ALL " + "SELECT MAX(" + BaseColumns.COLUMN_ID + ") FROM " + Course.TABLE_NAME +
        " UNION ALL " + "SELECT MAX(" + BaseColumns.COLUMN_ID + ") FROM " + Lesson.TABLE_NAME + ';';

    public static interface Nodes {
        // XML node name
        public static final String JOIN_NODE    = "join";
        public static final String GRADE_NODE   = "grade";
        public static final String COURSE_NODE  = "course";
        public static final String LESSON_NODE  = "lession";
        public static final String SUBJECT_NODE = "subject";
        //public static final String VERSION_NODE = "version";

        // XML attributes name
        public static final String ATTRIB_ID   = "id";
        public static final String ATTRIB_NAME = "name";
        public static final String ATTRIB_SORT = "sort";
        public static final String ATTRIB_URL  = "url";
        public static final String ATTRIB_TYPE = "type";
        public static final String ATTRIB_JOIN_ID    = "join_id";
        public static final String ATTRIB_GRADE_ID   = "grade_id";
        public static final String ATTRIB_COURSE_ID  = "course_id";
        public static final String ATTRIB_SUBJECT_ID = "subject_id";
        //public static final String ATTRIB_VERSION_ID = "version_id";
    };

    public static final class ColumnInfo {
        public static final int VALUE_TYPE_STRING  = 0;
        public static final int VALUE_TYPE_INTEGER = 1;

        public final String columnName;
        public final String attribName;
        public final int valueType;

        public ColumnInfo(String columnName, String attribName, int valueType) {
            this.valueType  = valueType;
            this.columnName = columnName;
            this.attribName = attribName;
        }
    }

    private static final ColumnInfo COLUMN_INFO_ID   = new ColumnInfo(BaseColumns.COLUMN_ID, Nodes.ATTRIB_ID, ColumnInfo.VALUE_TYPE_INTEGER);
    private static final ColumnInfo COLUMN_INFO_NAME = new ColumnInfo(BaseColumns.COLUMN_NAME, Nodes.ATTRIB_NAME, ColumnInfo.VALUE_TYPE_STRING);
    private static final ColumnInfo COLUMN_INFO_SORT = new ColumnInfo(BaseColumns.COLUMN_SORT_ORDER, Nodes.ATTRIB_SORT, ColumnInfo.VALUE_TYPE_INTEGER);

    public static final ColumnInfo[] BASE_COLUMNS_INFO = {
        COLUMN_INFO_ID, COLUMN_INFO_NAME, COLUMN_INFO_SORT,
    };

    public static final ColumnInfo[] JOIN_COLUMNS_INFO = { COLUMN_INFO_ID,
        new ColumnInfo(Join.COLUMN_GRADE_ID, Nodes.ATTRIB_GRADE_ID, ColumnInfo.VALUE_TYPE_INTEGER),
        new ColumnInfo(Join.COLUMN_SUBJECT_ID, Nodes.ATTRIB_SUBJECT_ID, ColumnInfo.VALUE_TYPE_INTEGER),
        //new ColumnInfo(Join.COLUMN_VERSION_ID, Nodes.ATTRIB_VERSION_ID, ColumnInfo.VALUE_TYPE_INTEGER),
    };

    public static final ColumnInfo[] COURSE_COLUMNS_INFO = {
        COLUMN_INFO_ID, COLUMN_INFO_NAME, COLUMN_INFO_SORT,
        new ColumnInfo(Course.COLUMN_JOIN_ID, Nodes.ATTRIB_JOIN_ID, ColumnInfo.VALUE_TYPE_INTEGER),
    };

    private Upgrade () {
    }
}